<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <!-- jQuery (Bootstrap 的所有 JavaScript 插件都依赖 jQuery，所以必须放在前边) -->
    <script src="https://cdn.jsdelivr.net/npm/jquery@1.12.4/dist/jquery.min.js" integrity="sha384-nvAa0+6Qg9clwYCGGPpDQLVpLNn0fRaROjHqs13t4Ggj3Ez50XnGQqc/r8MhnRDZ" crossorigin="anonymous"></script>

</head>
<body>
    <button id="findAll">调用findAll</button>
    <button id="findById">调用findById</button>
    <button id="add">调用add</button>
    <button id="update">调用update</button>
    <button id="delete">调用delete</button>
    <script>
        $("#findAll").click(function () {
            $.ajax({
                url:"http://localhost:8080/students",
                type:"get",
                dataType:"json",
                contentType:"application/json;charset=UTF-8",
                success(res){
                    console.log(res);
                }
            })
        });
        $("#findById").click(function () {
            $.ajax({
                url:"http://localhost:8080/student/" + 4,
                type:"get",
                dataType:"json",
                contentType:"application/json;charset=UTF-8",
                success(res){
                    console.log(res);
                }
            })
        });
        $("#add").click(function () {
            let stu = {id:6,name:"陈三",age:20,subject:"语文"};
            $.ajax({
                url:"http://localhost:8080/student",
                type:"post",
                data:JSON.stringify(stu),
                dataType:"json",
                contentType:"application/json;charset=UTF-8",
                success(res){
                    console.log(res);
                }
            })
        });
        $("#update").click(function () {
            let stu = {id:6,name:"陈三",age:20,subject:"语文"};
            $.ajax({
                url:"http://localhost:8080/student",
                type:"put",
                data:JSON.stringify(stu),
                dataType:"json",
                contentType:"application/json;charset=UTF-8",
                success(res){
                    console.log(res);
                }
            })
        });
        $("#delete").click(function () {
            $.ajax({
                url:"http://localhost:8080/student/1",
                type:"delete",
                dataType:"json",
                contentType:"application/json;charset=UTF-8",
                success(res){
                    console.log(res);
                }
            })
        });
    </script>
</body>
</html>